package com.xshiwu.springsecurty.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

// @Configuration
public class SecurtyConfig extends WebSecurityConfigurerAdapter {

    /**
     * 重写WebSecurityConfigurerAdapter里面的登录验证接口
     * @param auth 工厂配置类
     * @throws Exception 异常
     */
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String password = bCryptPasswordEncoder.encode("123456");
        System.out.println("password = " + password);
        auth.inMemoryAuthentication().withUser("xsw").password(password).roles("admin");
    }

    @Bean
    public PasswordEncoder password(){
        return new BCryptPasswordEncoder();
    }

}
